package com.example.web.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class StockAspect {

    private static final Logger logger = LoggerFactory.getLogger(StockAspect.class);

    // 定义切入点，匹配入库和出库服务方法
    @Pointcut("execution(* com.example.web.service.impl.StockInServiceImpl.*(..)) || execution(* com.example.web.service.impl.StockOutServiceImpl.*(..))")
    public void stockMethods() {}

    @Before("stockMethods()")
    public void beforeStockMethod(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        logger.info("Before executing stock method: {} with arguments: {}", methodName, args);
    }

    @After("stockMethods()")
    public void afterStockMethod(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        logger.info("After executing stock method: {}", methodName);
    }
}